package com.agritech;

import com.agritech.factory.*;
import com.agritech.observer.*;
import com.agritech.strategy.*;
import com.agritech.chain.*;
import com.agritech.machines.*;

public class Main {
    public static void main(String[] args) {
        // 创建环境监测器
        EnvironmentMonitor monitor = new EnvironmentMonitor();

        // 创建农机设备
        MachineFactory seederFactory = new SeederFactory();
        MachineFactory harvesterFactory = new HarvesterFactory();

        AgriculturalMachine seeder = seederFactory.createMachine("SEEDER_001", "智能播种机1号");
        AgriculturalMachine harvester = harvesterFactory.createMachine("HARVESTER_001", "智能收割机1号");

        // 注册观察者
        monitor.registerObserver(seeder);
        monitor.registerObserver(harvester);

        // 创建安全处理链
        SafetyHandler obstacleHandler = new ObstacleHandler();
        // 可以添加更多处理器并设置链

        // 模拟环境数据变化
        EnvironmentData data = new EnvironmentData();
        data.setSoilMoisture(85.0);
        data.setSoilPH(6.5);
        data.setTemperature(25.0);
        data.setHumidity(60.0);
        data.setWindSpeed(15.0);
        data.setCropStatus("正常生长");

        System.out.println("=== 系统启动 ===");

        // 通知观察者环境变化
        monitor.setEnvironmentData(data);

        // 模拟安全事件
        SafetyEvent obstacleEvent = new SafetyEvent();
        obstacleEvent.setType(SafetyEvent.EventType.OBSTACLE_DETECTED);
        obstacleEvent.setDescription("前方检测到大型障碍物");
        obstacleEvent.setSeverity(4);
        obstacleEvent.setMachineId("SEEDER_001");

        System.out.println("\n=== 处理安全事件 ===");
        obstacleHandler.handleSafetyEvent(obstacleEvent);

        // 测试路径规划策略
        PathPlanningStrategy normalStrategy = new NormalPathStrategy();
        PathPlanningStrategy emergencyStrategy = new EmergencyPathStrategy();

        System.out.println("\n=== 测试路径规划 ===");
        System.out.println(normalStrategy.calculatePath(30.5, 114.3, 30.6, 114.4, data));
        System.out.println(emergencyStrategy.calculatePath(30.5, 114.3, 30.6, 114.4, data));
    }
}